/////precompiled////////
#include "precompiled.h"
////////////////////////


#include "prs_FrmGeom.h"
using namespace prs;

// TNodeFrmGeom ///////////////////////////////////////////////////////////////

/**************
//
void TNodeFrmGeom::SetSize(EOrdinate Ordinate,TNodeFrmGeomSize &Value)
{
  TNodeFrmGeomSize *NewNode = static_cast<TNodeFrmGeomSize*>(Value.New());
  Value.NewAndCopyAttrTo(*NewNode);

  switch (Ordinate) {
    case EOrdinate_X: Width .SetValue(NewNode); break;
    case EOrdinate_Y: Height.SetValue(NewNode); break;
  }
}
******************/

/***************
//
void TNodeFrmGeom::SetSizeByName(EOrdinate Ordinate,svl::TString &Name)
{
  switch (Ordinate) {
    case EOrdinate_X: Width .SetValue(TNodeFrmGeomSize::NewByName(Name)); break;
    case EOrdinate_Y: Height.SetValue(TNodeFrmGeomSize::NewByName(Name)); break;
  }
}
**********************/
/***********
//
void TNodeFrmGeom::SetAlignByName(EOrdinate Ordinate,svl::TString &Name)
{
  switch (Ordinate) {
    case EOrdinate_X: WAlign.SetValue(TNodeFrmGeomAlign::WNewByName(Name)); break;
    case EOrdinate_Y: HAlign.SetValue(TNodeFrmGeomAlign::HNewByName(Name)); break;
  }
}
****************/
//
void TNodeFrmGeom::UnionWAlignTo(frm::geometry::TGeometry &To)
{
  TNodeFrmGeomAlign *PWAlign = WAlign.GetValue(); 
  if (PWAlign) {
    To.SetWAlign(PWAlign->NewOld());
  }
}

//
void TNodeFrmGeom::UnionHAlignTo(frm::geometry::TGeometry &To)
{
  TNodeFrmGeomAlign *PHAlign = HAlign.GetValue(); 
  if (PHAlign) {
    To.SetHAlign(PHAlign->NewOld());
  }
}

//
void TNodeFrmGeom::UnionWidthTo(frm::geometry::TGeometry &To)
{
  TNodeFrmGeomSize *PWidth = Width.GetValue(); 
  if (PWidth) {
    To.SetWidth(PWidth->NewOld());
  }
}

//
void TNodeFrmGeom::UnionHeightTo(frm::geometry::TGeometry &To)
{
  TNodeFrmGeomSize *PHeight = Height.GetValue(); 
  if (PHeight) {
    To.SetHeight(PHeight->NewOld());
  }
}

//
void TNodeFrmGeom::UnionDirectTo(frm::geometry::TGeometry &To)
{
  TNodeFrmGeomDirect *PDirect = Direct.GetValue(); 
  if (PDirect) {
    To.SetDirect(PDirect->NewOld());
  }
}

//
void TNodeFrmGeom::UnionBorderTo(frm::geometry::TGeometry &To)
{
  TNodeFrmGeomBorder *PBorder = Border.GetValue();
  
  if (PBorder) {
    To.SetWBorder(new frm::geometry::TRuleBorder(
      Border->Left .GetValue(),
      Border->Right.GetValue()
    ));
    To.SetHBorder(new frm::geometry::TRuleBorder(
      Border->Top   .GetValue(),
      Border->Bottom.GetValue()
    ));
  }
}

//
void TNodeFrmGeom::UnionTo(frm::geometry::TGeometry &To)
{
  UnionWAlignTo(To);
  UnionHAlignTo(To);
  UnionWidthTo(To);
  UnionHeightTo(To);
  UnionDirectTo(To);
  UnionBorderTo(To);
}

// TRuleFrmGeom ///////////////////////////////////////////////////////////////

//
TRuleFrmGeom::TRuleFrmGeom(
  snt::text::TContext &SntContext
) 
:RGeomSize  (SntContext)
,RGeomDirect(SntContext)
,RGeomAlign (SntContext)
{
  snt::TReturn Return;
  snt::TFVoid F;
  //snt::text::TSequence T(SntContext);
  //snt::text::TNumber   N(SntContext);
  //snt::text::TIdent    I(SntContext);

  this->Name(GetClassName())
  | F.New(this,&TRuleFrmGeom::FSetAttrWidth)
    & RGeomSize.RWidth.New()
    & Return.New()
    
  | F.New(this,&TRuleFrmGeom::FSetAttrHeight)
    & RGeomSize.RHeight.New()
    & Return.New()

  | F.New(this,&TRuleFrmGeom::FSetAttrDirect)
    & RGeomDirect.RDirect.New()
    & Return.New()
    
  | F.New(this,&TRuleFrmGeom::FSetAttrWAlign)
    & RGeomAlign.RWAlign.New()
    & Return.New()
    
  | F.New(this,&TRuleFrmGeom::FSetAttrHAlign)
    & RGeomAlign.RHAlign.New()
    & Return.New()
  ;
}

//
void TRuleFrmGeom::FSetAttrWidth(snt::TParams &Params)
{
  RGeomSize.SetAttr(&geom->Width);
}

//
void TRuleFrmGeom::FSetAttrHeight(snt::TParams &Params)
{
  RGeomSize.SetAttr(&geom->Height);
}

//
void TRuleFrmGeom::FSetAttrDirect(snt::TParams &Params)
{
  RGeomDirect.SetAttr(&geom->Direct);
}

//
void TRuleFrmGeom::FSetAttrWAlign(snt::TParams &Params)
{
  RGeomAlign.SetAttr(&geom->WAlign);
}

//
void TRuleFrmGeom::FSetAttrHAlign(snt::TParams &Params)
{
  RGeomAlign.SetAttr(&geom->HAlign);
}
